package com.homwork;

import java.io.*;
import java.util.HashMap;
import java.util.HashSet;

public class Text1 {
    public static void main(String[] args) throws IOException {
            Text1.wordNum(new File("t1.txt"),new File("t2.txt"));

    }
    public static void wordNum(File file1,File file2)throws IOException{

        FileReader fb=  new FileReader(file1);
        HashMap <String,Integer>hashmap  =    new HashMap();
        char[] char2 = new char[1];
        HashSet hashset=new HashSet();

        int len=0;
        while((len=fb.read(char2))!=-1){
            String char1=     new String(char2);
            if(hashset.add(char1)){
                hashmap.put(char1,1);
            }
        else
            hashmap.put(char1,hashmap.get(char1)+1);
        }
        FileWriter output = new FileWriter(file2);
        for(String set: hashmap.keySet()){
            output.write("字母"+set+"次数"+hashmap.get(set));
        }
        output.close();
    }

}




